memcpy(stack_regs, &n->arch.user_regs, CTXT_SWITCH_STACK_BYTES);
if ( xsave_enabled(n) && n->arch.xcr0 != get_xcr0() )
set_xcr0(n->arch.xcr0);
+ vcpu_restore_fpu_eager(n);
n->arch.ctxt_switch_to(n);
}
static void vmx_fpu_enter(struct vcpu *v)
{
- vcpu_restore_fpu(v);
+ vcpu_restore_fpu_lazy(v);
v->arch.hvm_vmx.exception_bitmap &= ~(1u << TRAP_no_device);
vmx_update_exception_bitmap(v);
v->arch.hvm_vmx.host_cr0 &= ~X86_CR0_TS;
/* FPU Save Functions */
/*******************************/
/* Save x87 extended state */
-static inline void fpu_xsave(struct vcpu *v, uint64_t mask)
+static inline void fpu_xsave(struct vcpu *v)
{
/* XCR0 normally represents what guest OS set. In case of Xen itself,
* we set all accumulated feature mask before doing save/restore.
*/
set_xcr0(v->arch.xcr0_accum);
- xsave(v, mask);
+ xsave(v, v->arch.nonlazy_xstate_used ? XSTATE_ALL : XSTATE_LAZY);
set_xcr0(v->arch.xcr0);
}
/*******************************/
/* VCPU FPU Functions */
/*******************************/
+/* Restore FPU state whenever VCPU is schduled in. */
+void vcpu_restore_fpu_eager(struct vcpu *v)
+{
+ ASSERT(!is_idle_vcpu(v));
+
+ /* save the nonlazy extended state which is not tracked by CR0.TS bit */
+ if ( v->arch.nonlazy_xstate_used )
+ {
+ /* Avoid recursion */
+ clts();
+ fpu_xrstor(v, XSTATE_NONLAZY);
+ stts();
+ }
+}
+
/*
* Restore FPU state when #NM is triggered.
*/
-void vcpu_restore_fpu(struct vcpu *v)
+void vcpu_restore_fpu_lazy(struct vcpu *v)
{
ASSERT(!is_idle_vcpu(v));
return;
if ( xsave_enabled(v) )
- fpu_xrstor(v, XSTATE_ALL);
+ fpu_xrstor(v, XSTATE_LAZY);
else if ( v->fpu_initialised )
{
if ( cpu_has_fxsr )
clts();
if ( xsave_enabled(v) )
- fpu_xsave(v, XSTATE_ALL);
+ fpu_xsave(v);
else if ( cpu_has_fxsr )
fpu_fxsave(v);
else
* it explicitly enables it via xcr0.
*/
uint64_t xcr0_accum;
-
+ /* This variable determines whether nonlazy extended state has been used,
+ * and thus should be saved/restored. */
+ bool_t nonlazy_xstate_used;
+
struct paging_vcpu paging;
#ifdef CONFIG_X86_32
#include <xen/types.h>
#include <xen/percpu.h>
-void vcpu_restore_fpu(struct vcpu *v);
+void vcpu_restore_fpu_eager(struct vcpu *v);
+void vcpu_restore_fpu_lazy(struct vcpu *v);
void vcpu_save_fpu(struct vcpu *v);
int vcpu_init_fpu(struct vcpu *v);